package pl.pawluk.inz.web;

import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import pl.pawluk.inz.dao.IUsersService;
import pl.pawluk.inz.dto.UserDTO;
import pl.pawluk.inz.security.AuthenticationService;

/**
 * Created with IntelliJ IDEA.
 * User: mandp
 * Date: 23.05.13
 * Time: 15:32
 * To change this template use File | Settings | File Templates.
 */
@Component
@Scope("session")
public class LoginInfoBean extends BaseBean {

    private UserDTO loggedUser;

    @Autowired
    private IUsersService userService;
    @Autowired
    private AuthenticationService authenticationService;


    public UserDTO getUser() {
        if (loggedUser == null) {
            loggedUser = userService.getUserInfo(authenticationService.getUserName());
        }
        return loggedUser;
    }

    @Override
    protected void insertOrUpdate() {
    }

    @Override
    public void onRowUnselect(UnselectEvent event) {
    }

    @Override
    public void onRowSelect(SelectEvent event) {
    }

    @Override
    public void createNew() {
    }

    @Override
    public void delete() {
    }

    public void logout() {
        authenticationService.logout();
    }
}
